<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">选择问答分类</h4>
			</div>
			<div class="modal-body"  id="treeChooseTypeBoxId">
				<div id="loadingDivId">加载分类中...</div>
				<ul class="doctypeUl" style="max-height: 400px; overflow: auto;">
					
				</ul>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					关闭</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<script type="text/javascript">
var type_collapse_level=3;
</script>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="1">
<script type="text/javascript">
var type_collapse_level=1;
</script>
</PF:IfParameterEquals>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="2">
<script type="text/javascript">
var type_collapse_level=2;
</script>
</PF:IfParameterEquals>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="3">
<script type="text/javascript">
var type_collapse_level=3;
</script>
</PF:IfParameterEquals>
<script type="text/javascript">
	$(function() {
		$.post('webtype/PubLoadFqaWType.html',{typeid:'${doc.type.id}${doce.type.id}'}, function(flag) {
			var ishaveType=false;
			var typeobj=$.parseJSON(flag);
			if(typeobj.types.length==0){
				$('#loadingDivId').html("<div class='alert alert-warning'>无分类信息<br/>请在后台添加分类!</div>");
			}
			//第一层 
			$(typeobj.types).each(function(i, obj1) {
				if (obj1.parentid == "NONE") {
					var html = new Array();
					html.push("<li>");
					html.push('<h5 class="showLableType">');
					if(obj1.type=='1'){
						html.push('<font style="color: #8f8f8f">' + obj1.name + '</font>');
					}
					if(obj1.type=='3'){
						html.push('<a id='+obj1.id+'>' + obj1.name + '</a>');
					}
					if (obj1.num > 0) {
						html.push('<span style="color: #D9534F; font-weight: bold;">',obj1.num,'</span>');
					}
					if(type_collapse_level<=1){
						html.push('<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj1.id,'"></a>');
					}
					html.push('</h5>');
					html.push('<ul>');
					//第二层
					$(typeobj.types).each(function(i, obj2) {
						if(obj2.parentid==obj1.id) {
							html.push("<li>");
							html.push('<h5 class="showLableType">');
							if(obj2.type=='1'){
								html.push('<font style="color: #8f8f8f">' + obj2.name + '</font>');
							}
							if(obj2.type=='3'){
								html.push('<a id='+obj2.id+'>' + obj2.name + '</a>');
							}
							if (obj2.num > 0) {
								html.push('<span style="color: #D9534F; font-weight: bold;">',obj2.num,'</span>');
							}
							if(type_collapse_level<=2){
								html.push('<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj2.id,'"></a>');
							}
							html.push('</h5>');
							html.push('<ul>');
							//第三层
							$(typeobj.types).each(function(i, obj3) {
								if(obj3.parentid==obj2.id) {
									html.push("<li>");
									html.push('<h5 class="showLableType">');
									if(obj3.type=='1'){
										html.push('<font style="color: #8f8f8f">' + obj3.name + '</font>');
									}
									if(obj3.type=='3'){
										html.push('<a id='+obj3.id+'>' + obj3.name + '</a>');
									}
									if (obj3.num > 0) {
										html.push('<span style="color: #D9534F; font-weight: bold;">',obj3.num,'</span>');
									}
									if(type_collapse_level<=3){
										html.push('<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj3.id,'"></a>');
									}
									html.push('</h5>');
									html.push('<ul>');
									//第四层
									$(typeobj.types).each(function(i, obj4) {
										if(obj4.parentid==obj3.id) {
											html.push("<li>");
											html.push('<h5 class="showLableType">');
											if(obj4.type=='1'){
												html.push('<font style="color: #8f8f8f">' + obj4.name + '</font>');
											}
											if(obj4.type=='3'){
												html.push('<a id='+obj4.id+'>' + obj4.name + '</a>');
											}
											if (obj4.num > 0) {
												html.push('<span style="color: #D9534F; font-weight: bold;">',obj4.num,'</span>');
											}
											html.push('<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj4.id,'"></a>');
											html.push('</h5>');
											html.push('<ul>');
											//第五层
											$(typeobj.types).each(function(i, obj5) {
												if(obj5.parentid==obj4.id) {
													html.push("<li>");
													html.push('<h5 class="showLableType">');
													if(obj5.type=='1'){
														html.push('<font style="color: #8f8f8f">' + obj5.name + '</font>');
													}
													if(obj5.type=='3'){
														html.push('<a id='+obj5.id+'>' + obj5.name + '</a>');
													}
													if (obj5.num > 0) {
														html.push('<span style="color: #D9534F; font-weight: bold;">',obj5.num,'</span>');
													}
													html.push('<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj5.id,'"></a>');
													html.push('</h5>');
													html.push("</li>");
												}
											});
											html.push('</ul>');
											html.push("</li>");
										}
									});
									html.push('</ul>');
									html.push("</li>");
								}
							});
							html.push('</ul>');
							html.push("</li>");
						}
					});
					html.push('</ul>');
					html.push("</li>");
					$('#loadingDivId').html("");
					$('.doctypeUl').append(html.join(""));
					ishaveType=true;
					//html.push('');
				}
			});
			//alert(typeobj.types.length);
			initTypesStyle();
			$(typeobj.typepath).each(function(i,obj){
				$('.'+obj.id).click();
			});
		});
	});
	function initTypesStyle(){
		$('a', '.showLableType').bind(
				'click',
				function() {
					if ($(this).attr('id')) {
						$('#knowtypeId').val($(this).attr('id'));
						$('#knowtypeTitleId').val($(this).text());
						$('#myModal').modal('hide');
						try{
							typeInputUpdate();
						}catch(e){
							//无实现回调函数
						}
					}
				});

		$('.farm_tree_flag').each(function(i, o) {
			if ($(this).parent().next().contents().length <= 1) {
				$(this).removeClass("farm_tree_flag");
				$(this).removeClass("glyphicon");
				$(this).removeClass("glyphicon-chevron-down");
			} else {
				$(this).parent().next().hide();
			}
		});
		$('.farm_tree_flag').bind('click', function() {
			var ul = $(this).parent().next();
			if ($(ul).is(':hidden')) {
				$(this).parent().next().show();
				$(this).removeClass("farm_tree_s");
				$(this).addClass("farm_tree_h");
				$(this).removeClass("glyphicon-chevron-down");
				$(this).addClass("glyphicon-chevron-up");
			} else {
				$(this).parent().next().hide();
				$(this).removeClass("farm_tree_h");
				$(this).addClass("farm_tree_s");
				$(this).removeClass("glyphicon-chevron-up");
				$(this).addClass("glyphicon-chevron-down");
			}
		});
	}
</script>